package controllers

import (
	"fmt"
	"github.com/astaxie/beego/httplib"
	"github.com/astaxie/beego/logs"
	"github.com/eclipse/paho.mqtt.golang"
	"smart_home/mqtt/conf"
	"smart_home/mqtt/system"
)

type SwitchStatusController struct {
	system.Controller
}

func (c *SwitchStatusController) Exece(client mqtt.Client, message mqtt.Message, clientId string) {
	logs.Debug("topic:", message.Topic(), " / Retained:", message.Retained())
	_, err := httplib.Post(fmt.Sprintf("%s/v2/mqtt/equipment_log", conf.ApiHost)).
		Param("sta", clientId).Param("act", string(message.Payload())).Response()
	if err != nil {
		logs.Error(err)
	}
}
